﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Help;
using Model;
using Bll;

namespace Myproject.BSM.Ashx.PcBase
{
    /// <summary>
    /// NavigationEdit 的摘要说明
    /// </summary>
    public class NavigationEdit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Form["pc_base_navEdit_navID"];
            string name = context.Request.Form["pc_base_navEdit_name"];
            string ename = context.Request.Form["pc_base_navEdit_ename"];
            string url = context.Request.Form["pc_base_navEdit_url"];
            string eurl = context.Request.Form["pc_base_navEdit_eurl"];
            string rank = context.Request.Form["pc_base_navEdit_frank"];
            string rank2 = context.Request.Form["pc_base_navEdit_srank"];
            string pid = context.Request.Form["pc_base_navEdit_parentID"];
            if (id == "0")
            {
                NavModel model = new NavModel();
                model.Title = name;
                model.ETitle = ename;
                model.Url = url;
                model.EUrl = eurl;
                model.FatherRank = int.Parse(rank);
                model.SonRank = int.Parse(rank2);
                model.ParentID = int.Parse(pid);
                if (new NavBLL().Add(model) > 0)
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "添加导航成功！", "pc_base_Navigation", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "添加导航失败！", "pc_base_Navigation", "", "", true, "", ""));
                }
            }
            else
            {
                NavModel model = new NavBLL().GetModel(int.Parse(id));
                model.Title = name;
                model.ETitle = ename;
                model.Url = url;
                model.EUrl = eurl;
                model.FatherRank = int.Parse(rank);
                model.SonRank = int.Parse(rank2);
                model.ParentID = int.Parse(pid);
                if (new NavBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改导航成功！", "pc_base_Navigation", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改导航失败！", "pc_base_Navigation", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}